﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TurtleLib.Simulation
{
  public class Point3D
  {
    public int X { get; protected set; }
    public int Y { get; protected set; }
    public int Z { get; protected set; }

    public Point3D(int x, int y, int z)
    {
      X = x;
      Y = y;
      Z = z;
    }

    public static bool operator ==(Point3D lhs, Point3D rhs)
    {
      return
        (object)rhs != null &&
        lhs.X == rhs.X &&
        lhs.Y == rhs.Y &&
        lhs.Z == rhs.Z;
    }

    public static bool operator !=(Point3D lhs, Point3D rhs)
    {
      return !(lhs == rhs);
    }

    public override int GetHashCode()
    {
      return X.GetHashCode() ^ Y.GetHashCode() ^ Z.GetHashCode();
    }

    public override bool Equals(object obj)
    {
      Point3D rhs = obj as Point3D;
      if ((object)rhs == null)
        return false;

      return this == rhs;
    }

    public Point3D Offset(int dx, int dy, int dz)
    {
      return new Point3D(X + dx, Y + dy, Z + dz);
    }

    public override string ToString()
    {
      if ((object)this == null)
        return "null";

      return string.Format("[{0}, {1}, {2}]", X, Y, Z);
    }
  }
}
